package com.example.controller;

import com.example.common.Result;
import com.example.entity.Score;
import com.example.service.ScoreService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前端请求接口
 */
@ApiSupport(author = "wjp", order = 3)
@Tag(name = "评分管理", description = "评分的增删改查接口")
@RestController
@RequestMapping("/score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    /**
     * 新增
     */
    @PostMapping("/add")
    @Operation(summary = "新增评分", description = "创建一条新的评分")
    public Result add(@RequestBody Score score) {
        scoreService.add(score);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @Operation(summary = "修改评分", description = "根据ID修改评分内容")
    public Result update(@RequestBody Score score) {
        scoreService.updateById(score);
        return Result.success();
    }

    /**
     * 单个删除
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除评分", description = "根据ID删除评分")
    public Result delete(@Parameter(description = "评分ID") @PathVariable Integer id) {
        scoreService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    @Operation(summary = "批量删除评分", description = "根据ID集合批量删除评分")
    public Result delete(@RequestBody List<Integer> ids) {
        scoreService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 单个查询
     */
    @GetMapping("/selectById/{id}")
    @Operation(summary = "查询评分", description = "根据ID查询评分详情")
    public Result selectById(@Parameter(description = "评分ID") @PathVariable Integer id) {
        Score score = scoreService.selectById(id);
        return Result.success(score);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    @Operation(summary = "查询所有评分", description = "获取评分列表，可根据条件查询")
    public Result selectAll(Score score) {
        List<Score> list = scoreService.selectAll(score);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    @Operation(summary = "分页查询评分", description = "分页获取评分列表")
    public Result selectPage(Score score,
                             @Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
                             @Parameter(description = "每页条数") @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Score> pageInfo = scoreService.selectPage(score, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    /**
     * 当前用户是否评分过这个壁纸
     */
    @GetMapping("/isScore")
    @Operation(summary = "当前用户是否评分过这个壁纸", description = "当前用户是否评分过这个壁纸")
    public Result isScore(String userId, Integer goodsId) {
        List<Score> list = scoreService.isScore(userId, goodsId);
        return Result.success(list);
    }

}
